package JDK8;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamDemo02 {
    public static void main(String[] args) {
        List<Integer> list1 = Arrays.asList(10, 8, 3, 11, 15, 7, 9, 6);
        // 求奇数的个数
        long count = list1.stream()
                .filter(x->x%2!=0)
                .count();
        System.out.println(count);

        // 求偶数和
        int sum = list1.stream()
                .filter(x->x%2==0)
                .mapToInt(x->x)
                .sum();
        System.out.println(sum);

        sum = list1.stream()
                .filter(x->x%2==0)
                .reduce(0,(x,y)->x+y);
        System.out.println(sum);

    }
}
